/*
 * parcelable_poi_info.cpp
 *
 *  Created on: Apr 3, 2018
 *      Author: sunjianguang
 */
#include "android/poi/parcelable_home_location.h"

#include <binder/Parcel.h>

namespace android {
namespace poi {

ParcelableHomeLocation::ParcelableHomeLocation(double longitude, double latitude, String16 home_name) {
    m_longitude = longitude;
    m_latitude = latitude;
    m_home_name = home_name;
}

/*inline std::string String16::std_string(const String16& str)
{
    return std::string(String8(str).string());
}*/
ParcelableHomeLocation::~ParcelableHomeLocation() {}

status_t ParcelableHomeLocation::writeToParcel(Parcel* parcel) const {
    status_t res;
    if (parcel == nullptr)
        return BAD_VALUE;
    res = parcel->writeDouble(m_longitude);
    if (res != OK)
        return res;
    res = parcel->writeDouble(m_latitude);
    if (res != OK)
        return res;
    res = parcel->writeString16(m_home_name);
    return res;
}

status_t ParcelableHomeLocation::readFromParcel(const Parcel* parcel) {
    status_t res;
    if (parcel == nullptr)
        return BAD_VALUE;
    res = parcel->readDouble(&m_longitude);
    if (res != OK)
        return res;
    res = parcel->readDouble(&m_latitude);
    if (res != OK)
        return res;
    m_home_name = readMaybeEmptyString16(parcel);
    return res;
}


String16 ParcelableHomeLocation::readMaybeEmptyString16(const Parcel* parcel) {
    size_t len;
    const char16_t* str = parcel->readString16Inplace(&len);
    if (str != nullptr) {
        return String16(str, len);
    } else {
        return String16();
    }
}
}  // namespace poi
}  // namespace android



